package org.jvnc.rfb.proto.encoding;

/**
* <br><br><center><table border="1" width="80%"><hr>
* <p>
* Copyright (C) 2006-2007 by Deon Wu
* <p>
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.0
* of the License, or (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* <a href="http://www.gnu.org/licenses/old-licenses/gpl-2.0.html">GNU Lesser General Public License</a>
* for more details.
* <p>
* You should have received a copy of the <a href="http://www.gnu.org/licenses/old-licenses/gpl-2.0.html">
* GNU Lesser General Public License</a> along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* <hr></table></center>
* **/

import java.awt.Color;
import java.awt.Image;
import java.awt.image.ColorModel;
import java.awt.image.DirectColorModel;
import java.io.DataInput;
import java.io.IOException;

import org.jvnc.logging.VLog;
import org.jvnc.rfb.proto.Rectangle;

public abstract class Encoding {
	protected static final VLog log = VLog.getLog(Encoding.class);
	public static final int RAW = 0;
	public static final int CopyRect = 1;
	public static final int RRE = 2;
	public static final int Hextile = 5;
	public static final int ZRLE = 16;
	public static final int Cursor = -239;
	
	private int type;
	protected Rectangle rect = null;
	protected static Color[] color265 = null;
	
	public abstract void fillEncoding(DataInput in) throws IOException;

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}
	
	/**
	 * 将当前编码格式转换为一个Image对象。
	 * @param frame RFB缓冲帧。
	 * @return
	 */
	public abstract Image deCode(Image frame);
	
	public void genRGBColors(){
		if(color265 == null){
			ColorModel cm8 = new DirectColorModel(8, 7, (7 << 3), (3 << 6));
			color265 = new Color[256];
		    for (int i = 0; i < 256; i++)
		    	color265[i] = new Color(cm8.getRGB(i));
		}
	}	
}
